package com.niit.activity.controller;

import com.niit.activity.entity.Topic;
import com.niit.activity.service.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/topics")
public class TopicController {
    @Autowired
    private TopicService topicService;

    /**
     * 添加话题
     * @param topic 话题对象
     */
    @PostMapping
    public void addTopic(@RequestBody Topic topic) {
        topicService.addTopic(topic);
    }

    /**
     * 获取所有话题列表
     * @return 话题列表
     */
    @GetMapping
    public List<Topic> getAllTopics() {
        return topicService.getAllTopics();
    }
    /**
     * 增加话题计数
     * @param topicId 话题ID
     */
    @PostMapping("/{topicId}/increment")
    public void incrementTopicNum(@PathVariable Long topicId) {
        topicService.updateTopicNum(topicId);
    }

    /**
     * 减少话题计数
     * @param topicId 话题ID
     */
    @PostMapping("/{topicId}/decrement")
    public void decrementTopicNum(@PathVariable Long topicId) {
        topicService.decreaseTopicNum(topicId);
    }

}